﻿using System;
using PicoContainer;
using PicoContainer.Defaults;

namespace Garfield.Runtime.Pico
{
    class ComponentAdapterFactory : IComponentAdapterFactory
    {
        private readonly PlatformProvider provider;
        private readonly bool isCaching;

        public ComponentAdapterFactory(bool isCaching)
        {
            this.isCaching = isCaching;
        }

        public ComponentAdapterFactory(PlatformProvider provider, bool isCaching)
        {
            this.provider = provider;
            this.isCaching = isCaching;
        }

        public IComponentAdapter CreateComponentAdapter(object componentKey, Type componentImplementation, IParameter[] parameters)
        {
            IComponentAdapter adapter = new ComponentAdapter(provider, componentKey, componentImplementation, parameters);
            return isCaching ? new CachingComponentAdapter(adapter) : adapter;
        }
    }
}
